# Contributor: TBK <alpine@jjtc.eu>
# Maintainer: TBK <alpine@jjtc.eu>
pkgname=commons-daemon
pkgver=1.3.4
pkgrel=0
pkgdesc="Tools to allow Java programs to run as UNIX daemons"
url="https://commons.apache.org/daemon/"
# riscv64 blocked by java-jdk
arch="all !riscv64"
license="Apache-2.0"
options="!check" # No test suite
depends="java-jre-headless"
makedepends="docbook2x libcap-dev linux-headers maven java-jdk"
subpackages="$pkgname-doc jsvc:_jsvc jsvc-doc:_jsvc_doc"
source="https://mirrors.dotsrc.org/apache/commons/daemon/source/commons-daemon-$pkgver-src.tar.gz
	rat_workaround.patch
	"
builddir="$srcdir/$pkgname-$pkgver-src"

build() {
	# commons-daemon.jar
	mvn install -DskipTests=true -Dmaven.javadoc.skip=false -B

	# jsvc
	cd "$builddir/src/native/unix"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--with-java=/usr/lib/jvm/default-jvm \
		CFLAGS="$CFLAGS -I/usr/lib/jvm/default-jvm/include/linux"
	make

	# jsvc manpage
	db2x_xsltproc -s man man/jsvc.1.xml -o jsvc.1
	gzip -9 jsvc.1
}

package() {
	install -Dm644 target/$pkgname-$pkgver.jar \
		"$pkgdir"/usr/share/java/$pkgname-$pkgver.jar
	ln -s $pkgname-$pkgver.jar "$pkgdir"/usr/share/java/$pkgname.jar
}

doc() {
	default_doc

	mkdir -p "$subpkgdir"/usr/share/doc/$pkgname
	cp -a "$builddir"/src/docs/* "$subpkgdir"/usr/share/doc/$pkgname/
	cp -a "$builddir"/src/samples "$subpkgdir"/usr/share/doc/$pkgname/
}

_jsvc() {
	pkgdesc="Executes classfile that implements a Daemon interface"
	url="https://commons.apache.org/proper/commons-daemon/jsvc.html"
	depends="$pkgname libcap"

	cd "$builddir/src/native/unix"
	install -Dm755 jsvc "$subpkgdir"/usr/bin/jsvc
}

_jsvc_doc() {
	cd "$builddir/src/native/unix"
	install -Dm644 jsvc.1.gz "$subpkgdir"/usr/share/man/man1/jsvc.1.gz
}

sha512sums="
bb36d88bc21a5777245012b2a73ee0e764b85715731f54cc4ff09343e95ccb18fc6c68b3ae9c680fb45a60c7ef5ed0f9e40991c2c03246dd7f8dd65031eddf24  commons-daemon-1.3.4-src.tar.gz
3e64d521e8ed7c6a1ff6b67911087e6553edddbd847c13633ec773cfcdc5486ddd24d9e6a518493bef1855741445bb92d149d8bfdd2d5fb1ae6af4ad4d211426  rat_workaround.patch
"
